package com.hos.operation.api;


import com.hos.db.create.CreateManager;
import com.hos.db.manager.PatsManager;
import com.hos.net.DictionariesService;
import com.hos.net.req.BaseReq;
import com.hos.net.req.pat.PatRegisterReq;
import com.hos.net.res.MsgHint;
import com.hos.utile.JsonUtile;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class ApiAppController extends ApiBase {

    @RequestMapping(value = "/app", method = RequestMethod.POST,
            produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String app(HttpServletRequest request, @RequestBody String json) {
        BaseReq req = isVerifyDataJson(request, json,"app");
        if (!req.isVerify) {
            return req.errorMsg;
        }
        //
        String service = req.service;
        String response = "";

        switch (service) {
            case DictionariesService.HOS_PAT_REG:
                //患者注册
                PatRegisterReq regReq = (PatRegisterReq) JsonUtile.json2Obj(json, PatRegisterReq.class);
                if (!regReq.isVerifyParameter()) {
                    return regReq.hint;
                }
                response = PatsManager.getInstance()
                        .userRegisterReq(getJdbcTemplate(), regReq);
                break;
            case DictionariesService.HOS_MSG_PUSH:
                //推送
                //PushReq pushReq = (PushReq) JsonUtile.json2Obj(json, PushReq.class);
                //response = PushManager.getInstance().onPush(pushReq);
                break;
            case DictionariesService.HOS_TAB_CREATE:
                //创建表
                new CreateManager(getJdbcTemplate()).caretePatTable();
                break;
            default:
                response = new MsgHint("请求未定义").toJson();
                break;
        }
        return response;
    }

}
